/**
 * $Id: UserDaoImpl.java 9 2010-11-02 15:31:06Z feigme $
 */
package com.iary.dao.impl;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.iary.core.Constants;
import com.iary.core.orm.hibernate.HibernateDao;
import com.iary.dao.UserDao;
import com.iary.entity.User;

@Repository
public class UserDaoImpl extends HibernateDao<User, Long> implements UserDao {

	/* (non-Javadoc)
	 * @see com.iary.dao.UserDao#createUser(com.iary.entity.User)
	 */
	public boolean createUser(User user) {
		save(user);
		return user.getId() == null ? false : true;
	}

	/* (non-Javadoc)
	 * @see com.iary.dao.UserDao#getUserByName(java.lang.String)
	 */
	public User getUserByName(String name) {
		return findUnique(Restrictions.eq("status", Constants.STATUS_VALID), Restrictions.eq("name", name));
	}

	/* (non-Javadoc)
	 * @see com.iary.dao.UserDao#getAllStatusUserByEmail(java.lang.String)
	 */
	public User getAllStatusUserByEmail(String email) {
		return findUniqueBy("email", email);
	}

	/* (non-Javadoc)
	 * @see com.iary.dao.UserDao#getAllStatusUserByName(java.lang.String)
	 */
	public User getAllStatusUserByName(String name) {
		return findUniqueBy("name", name);
	}

	/* (non-Javadoc)
	 * @see com.iary.dao.UserDao#getUserByEmail(java.lang.String)
	 */
	public User getUserByEmail(String email) {
		return findUnique(Restrictions.eq("status", Constants.STATUS_VALID), Restrictions.eq("email", email));
	}

}
